package cn.netbox.springmvc.dao;

import cn.netbox.springmvc.entity.User;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.Map;

@Repository
public class UserDao {
    private Map userMap=new HashMap<Integer, User>();
    {
        userMap.put(1,new User(1,"猪猪侠","ggbong"));
        userMap.put(2,new User(2,"超人强","asddsa"));
        userMap.put(3,new User(3,"波比","666666"));
    }
    public User selectUserById(int id){
        return (User) userMap.get(id);
    }

    public Map<Integer, User> getAllUser() {
        return userMap;
    }

    public void create(User user) {
        userMap.put(user.getId(), user);
    }

    public void deletUserById(int id) {
        userMap.remove(id);
    }

    public void updateUser(User user) {
        userMap.remove(user.getId());
        userMap.put(user.getId(), user);
    }
}
